import {
	get,
	post,
	Delete
} from 'utils/requests'

/* 获取商品列表 */
export const getIndexList = (pageNo, pageSize) => get({
	url: "/applet/index/getProductPageByEs",
	loading: true,
	data: {
		pageNo,
		pageSize
	}
})

/* 商品下单 */
export const placeOrder = data => post({
	url: "/applet/index/details/placeOrder",
	loading: true,
	json: "json",
	data
})

/* 获取商品列表根据类型 0初级，1加工 */
export const getProductListByType = (type, pageNo, pageSize) => get({
	url: `/applet/index/getProductPageEsByType/${type}`,
	loading: true,
	data: {
		pageNo,
		pageSize
	}
})

/* 获取商品详细信息 */
export const getGoodsInfo = (goodsId, type) => post({
	// url: `/primaryProduct/getProductInfo/${goodsId}/${type}`,
	url: `/applet/index/details/getProductInfo/${type}/${goodsId}`
})

/* 获取首页广告列表 */
export const getBannerList = () => get({
	url: "/applet/index/advertisement/getAdvertisements"
})

/* 获取商家电话号码 */
export const getMerchantPhoneNumber = (type, id) => get({
	url: `/applet/index/details/getSellerTel/${type}/${id}`
})


/* 收藏商品 */
export const addGoodsCollect = (id, type) => post({
	url: '/applet/mine/collection/addProductCollection',
	data: {
		id,
		type
	}
})

/* 取消收藏商品 */
export const removeGoodsCollect = (id) => post({
	url: '/applet/mine/collection/cancelCollectionById',
	data: {
		productId:id
	}
})

/**
 * @function getProductByPage 
 * @description 获取发布的农产品
 * @param {Number} pageNo 请求的页码
 * @param {Number} pageSize 每次请求获取的数据长度
 * @param {Number} type 请求的类型 0 表示在售商品，1 预售商品
 * @return {Promise}
 */
export const getProductByPage = (pageNo,pageSize,type) => post({
	url: `/applet/mine/product-manage/getReleaseProductPageByType/${type}`,
	// url: `/applet/mine/release-manage/getReleaseProductPageByType/${type}`,
	data: {
		pageNo,
		pageSize
	},
	loading: true
})

/* 获取发布总数 */
export const getNumberOfReleases = type => get({
	// url: `/applet/mine/release-manage/getNumberOfReleases/${type}`,
	url:`/applet/mine/product-manage/getNumberOfReleases/${type}`,
})

/**
 * @function deleteProductById
 * @description 根据id删除农户发布的商品
 * @param {Number} id 产品id
 * @param {Number} status 状态(-1:审核,0:在售,1:预售)
 * @param {Number} type 类型(0：初级、1:加工)
 * @return {Promise}
 */
export const deleteProductById = (id,status,type) => Delete({
	url: `/applet/mine/product-manage/delReleaseProductById/${type}/${status}/${id}`
})

/**
 * @function releaseProductNowById
 * @description 根据商品id将预售的商品即刻发布
 * @param {Number} id 产品id
 * @param {Number} type 	类型(0：初级、1:加工)
 * @return {Promise}
 */
export const releaseProductNowById = (id,type) => post({
	url: `/applet/mine/product-manage/releaseProductNowById/${type}/${id}`
})


/* 发布初级预售 */
export const releasePreSellProduct = (data) => {
	return post({
		url: '/applet/index/release/releasePreSellProduct',
		data,
		json: "json",
	})
}

/* 发布初级在售 */
export const releaseOnSellProduct = (data) => {
	return post({
		url: '/applet/index/release/releaseOnSellProduct',
		data,
		json: "json",
	})
}

/* 发布加工在售 */
export const processingReleaseOnSellProduct = (data) => {
	console.log("加工")
	return post({
		url: '/applet/mine/processing-product/releaseOnSellProduct',
		data,
		json: "json",
	})
}

/* 修改农产品信息 */
export const modifyProductInfo = (data) => {
	return post({
		url: '/applet/mine/product-manage/modifyProductInfo',
		data,
		json: "json",
	})
}
